import request from '../utils/request'

export interface Department {
  id: number
  name: string
  code: string
  description: string
  is_active: boolean
  created_at: string
  updated_at: string
}

export interface DepartmentQueryParams {
  page?: number
  pageSize?: number
  is_active?: boolean
  search?: string
  ordering?: string
}

export const getDepartments = (params?: DepartmentQueryParams) => {
  return request({
    url: '/api/system/departments/',
    method: 'get',
    params: {
      page: params?.page,
      page_size: params?.pageSize,
      is_active: params?.is_active,
      search: params?.search,
      ordering: params?.ordering
    }
  })
}

export const createDepartment = (data: Partial<Department>) => {
  return request({
    url: '/api/system/departments/',
    method: 'post',
    data
  })
}

export const updateDepartment = (id: number, data: Partial<Department>) => {
  return request({
    url: `/api/system/departments/${id}/`,
    method: 'put',
    data
  })
}

export const deleteDepartment = (id: number) => {
  return request({
    url: `/api/system/departments/${id}/`,
    method: 'delete'
  })
} 